home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / comm / misc / easytransfer.lzh / EasyTransfer / AmigaSource / EasyAmiga.c next >
Encoding:
C/C++ Source or Header  |  1995-11-11  |  37.1 KB  |  1,413 lines

  1. /* EasyAmiga.c By Kamran Karimi.
  2.  
  3.    This program tranfers files between an Amiga and
  4.    a PC using a serial NULL modem cable. Another
  5.    Program should run on the PC.
  6.  
  7.    To make EasyAmiga, Remote.c, Local.c and Serial.c are
  8.    also needed.
  9.  
  10.    Compiled with SAS/C 6.50
  11.    1> sc EasyAmiga.c
  12.    1> slink lib:c.o EasyAmiga.o Remote.o Local.o Serial.o lib lib:sc.lib\
  13.             lib:amiga.lib
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #include <exec/types.h>
  22. #include <exec/memory.h>
  23.  
  24. #include <dos.h>
  25.  
  26. #include <intuition/intuition.h>
  27. #include <clib/exec_protos.h>
  28. #include <clib/dos_protos.h>
  29. #include <clib/intuition_protos.h>
  30. #include <clib/graphics_protos.h>
  31.  
  32. #include "EasyAmiga.h"
  33.  
  34. struct FInfo  {
  35.  struct FInfo *next,*prev;
  36.  byte Selected,type;
  37.  char name[32];
  38.  char data[MAXAMINFOLEN + 10];
  39. };
  40.  
  41. extern struct PacketStruct Packet; 
  42.  
  43. #define SERTESTLEN 255
  44. #define PACKET_SIZE 255
  45. struct PacketStruct
  46. {
  47.  UBYTE Len;
  48.  UBYTE Data[PACKET_SIZE + 2];
  49. };
  50.  
  51. extern LONG ReceivePacket(VOID),SendPacket(VOID),ConfigSerial(ULONG BAUD);
  52. extern LONG OpenSerial(VOID);
  53. extern VOID CloseSerial(VOID);
  54. extern VOID ClrSer(VOID);
  55.  
  56. extern LONG GetSynch(VOID),PutSynch(VOID);
  57. extern LONG OpenTimer(VOID);
  58. extern VOID CloseTimer(VOID);
  59.  
  60. extern LONG LocalDir(VOID);
  61. extern LONG LocalDel(VOID),LocalMKDir(char *Name),LocalCd(char *Path);
  62.  
  63. extern LONG RemoteMKDir(char *Name),RemoteDel(VOID),RemoteCd(char *Path);
  64. extern LONG RemoteDir(VOID),RemoteReceive(VOID),RemoteSend(VOID);
  65. extern VOID RemoteQuit(VOID);
  66. extern LONG CheckLink(VOID);
  67.  
  68. extern struct ExecBase *SysBase;
  69. struct IntuitionBase *IntuitionBase;
  70. struct GfxBase *GfxBase; 
  71. extern struct DOSBase *DOSBase;
  72. struct Window *MainWin;
  73. struct Screen *MainScr;
  74.  
  75. FILE *ConfigFile;
  76. char ConfigFileName[25] = {"S:EasyTransfer.Config"};
  77.  
  78. long OverWriteProtect = TRUE;
  79.  
  80. long NumDone;
  81. SHORT Active = -1;
  82. USHORT OldVPot[2],OldHPot[2],SelectPos,FileNum[2] = {0,0},HPos[2] = {0,0};
  83. struct FInfo *First[2] = { NULL, NULL };
  84. struct FInfo *ItemAddr[2][MAXFILENUM] = 
  85. {
  86.  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
  87.  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
  88. };
  89.  
  90. char OrigPath[250];
  91.  
  92. size_t FileBuffSize = 32000;
  93.  
  94. #define DEFUNIT     0
  95. #define DEFDELAY    3
  96. #define DEFCHECK    5
  97. #define DEFCHECKSUM 1
  98.  
  99. ULONG NowSec,NowMic;
  100.  
  101. char SerialName[SERNAMELEN];
  102. SHORT UnitNum;
  103. SHORT DelayTime;
  104. SHORT CheckTime;
  105. SHORT CheckSumTry;
  106. SHORT Method;
  107. SHORT MSpeed, CurrSpeed;
  108. SHORT Mode = BIN;
  109.  
  110. ULONG Speed[MAXHARDSPEED] = 
  111.   { 300, 600,1200,2400,4800,9600,19200,38400,57600,115200 };
  112.  
  113. SHORT Row = 0;
  114. LONG MessNum[MAXMESSAGE] = { -1, -1, -1, -1};
  115.  
  116.  
  117. VOID PrintFileName(char *Name)
  118. {
  119.  if(Name)
  120.   sprintf(TransFileName,"%-31.31s",Name);
  121.  else
  122.   sprintf(TransFileName,"%-31.31s"," "); 
  123.  PrintIText(MainWin->RPort, &TransFileText,0,0);
  124. }
  125.  
  126. VOID ShowRemainder(ULONG Transfered, ULONG Total)
  127. {
  128.  ULONG  newTransfered;
  129.  static ULONG prevTransfered = 0;
  130.  
  131.  if(Total == 0)
  132.  {
  133.   SetAPen(MainWin->RPort,0);
  134.   RectFill(MainWin->RPort,371,159,627,167);
  135.   prevTransfered = 0;
  136.  }  
  137.  else
  138.  {
  139.   if(Transfered > Total) Transfered = Total;
  140.   newTransfered = 256 * Transfered / Total;
  141.   if((newTransfered > (prevTransfered + 5)) || (Transfered == Total))
  142.   {
  143.    SetAPen(MainWin->RPort,3);
  144.    RectFill(MainWin->RPort,371,159,371 + newTransfered,167);
  145.    prevTransfered = newTransfered;
  146.   }
  147.  }
  148. }
  149.  
  150. VOID Message(LONG MessageNum)
  151.  LONG count;
  152.  static int Alt[4] = {11,8,11,8};
  153.  
  154.  if(MessageNum == -1) return;
  155.  if(MessageNum == CURR_SPEED)
  156.  {
  157.   for(count = 0; count < 6; count++) 
  158.    MessageT[MessageNum][count + 7] = SpeedTexts[CurrSpeed].IText[count];
  159.  } 
  160.  if(MessageNum == SPEED_DONE)
  161.  {
  162.   for(count = 0; count < 6; count++) 
  163.    MessageT[MessageNum][count + 12] = SpeedTexts[CurrSpeed].IText[count];
  164.  }
  165.  if(Row < MAXMESSAGE)
  166.  { 
  167.   if(Alt[Row] == 8) Alt[Row] = 11;
  168.   else Alt[Row] = 8;
  169.   if(Alt[Row] == 11)
  170.   {
  171.    strcpy(MessIntuiText[Row].IText," ");
  172.    PrintIText(MainWin->RPort, &MessIntuiText[Row],8,0);
  173.   }
  174.   strcpy(MessIntuiText[Row].IText,MessageT[MessageNum]);
  175.   PrintIText(MainWin->RPort, &MessIntuiText[Row],Alt[Row],0);
  176.   MessNum[Row] = MessageNum;
  177.   Row++;
  178.   return;
  179.  }
  180.  for(count = 0; count < MAXMESSAGE - 1; count++)
  181.  {
  182.   if(MessNum[count + 1] != -1)
  183.   {
  184.    if(Alt[count] == 8) Alt[count] = 11;
  185.    else Alt[count] = 8;
  186.    if(Alt[count] == 11)
  187.    {
  188.     strcpy(MessIntuiText[count].IText," ");
  189.     PrintIText(MainWin->RPort, &MessIntuiText[count],8,0);
  190.    }
  191.    strcpy(MessIntuiText[count].IText,MessIntuiText[count + 1].IText);
  192.    PrintIText(MainWin->RPort, &MessIntuiText[count],Alt[count],0);
  193.    MessNum[count] = MessNum[count + 1];
  194.   }
  195.  }
  196.  if(Alt[MAXMESSAGE - 1] == 8) Alt[MAXMESSAGE - 1] = 11;
  197.  else Alt[MAXMESSAGE - 1] = 8;
  198.  if(Alt[MAXMESSAGE - 1] == 11) 
  199.  {
  200.   strcpy(MessIntuiText[MAXMESSAGE - 1].IText," ");
  201.   PrintIText(MainWin->RPort, &MessIntuiText[MAXMESSAGE - 1],8,0);
  202.  }
  203.  strcpy(MessIntuiText[MAXMESSAGE - 1].IText,MessageT[MessageNum]);
  204.  PrintIText(MainWin->RPort,&MessIntuiText[MAXMESSAGE - 1],
  205.                                                       Alt[MAXMESSAGE - 1],0);
  206.  MessNum[MAXMESSAGE - 1] = MessageNum; 
  207. }
  208.  
  209.  
  210. VOID WaitPointer(VOID)
  211. {
  212.  RemoveGList(MainWin,PCSelect,MAXFILENUM);
  213.  RemoveGList(MainWin,AMSelect,MAXFILENUM);
  214.  RemoveGList(MainWin,Gads,AMHPROP);
  215.  SetPointer(MainWin, WaitPointerData, 16, 16, 0, 0);
  216. }
  217.  
  218. VOID NormalPointer(VOID)
  219. {
  220.  ClearPointer(MainWin);
  221.  AddGList(MainWin,Gads,-1,AMHPROP,NULL);
  222.  AddGList(MainWin,PCSelect,-1,MAXFILENUM,NULL);
  223.  AddGList(MainWin,AMSelect,-1,MAXFILENUM,NULL);
  224. }
  225.  
  226.  
  227. LONG PutSpeedMethodDelay(VOID)
  228. {
  229.  LONG Error,MinSpeed = MINSPEED - 1;
  230.  
  231.  if(ConfigSerial(Speed[MinSpeed])) return ERROR_SetSer;
  232.  Packet.Len = 1;
  233.  if(Method == BIOS)
  234.   Packet.Data[0] = 'B';
  235.  else 
  236.   Packet.Data[0] = 'H';
  237.  if((Error = SendPacket())) return Error;
  238.  if((Error = GetSynch())) return Error;
  239.  Packet.Len = 1;
  240.  Packet.Data[0] = CurrSpeed;
  241.  if((Error = SendPacket())) return Error;
  242.  if((Error = GetSynch())) return Error;
  243.  Packet.Len = 1;
  244.  Packet.Data[0] = DelayTime;
  245.  if((Error = SendPacket())) return Error;
  246.  if((Error = GetSynch())) return Error;
  247.  Packet.Len = 1;
  248.  Packet.Data[0] = CheckSumTry;
  249.  if((Error = SendPacket())) return Error;
  250.  if((Error = GetSynch())) return Error;
  251.  else return NO_ERROR;
  252. }
  253.  
  254.  
  255. LONG SetSerial(VOID)
  256. {
  257.  LONG Error,done = FALSE;
  258.  UBYTE count;
  259.  
  260.  do
  261.  {
  262.   Message(CURR_SPEED);
  263.   ClrSer();
  264.   Delay(150);
  265.   if(ConfigSerial(Speed[CurrSpeed])) return ERROR_SetSer;
  266.   if((Error = PutSynch())) return Error;
  267.   if((Error = GetSynch())) return Error;
  268.   Packet.Len = SERTESTLEN;
  269.   for(count = 0; count < SERTESTLEN; count++)
  270.    Packet.Data[count] = count;
  271.   if((Error = SendPacket())) return Error;
  272.   Packet.Len = 1;
  273.   if((Error = ReceivePacket())) return Error;
  274.   if(Packet.Data[0] == '!')
  275.   {
  276.    Message(SERVER_AGREED);
  277.    if((Error = PutSynch())) return Error;
  278.    Packet.Len = SERTESTLEN;
  279.    Error = ReceivePacket();
  280.    for(count = 0; count < SERTESTLEN; count++)
  281.     if(Packet.Data[count] != (UBYTE)(SERTESTLEN - count - 1)) break;
  282.    if((Error == ERROR_Timeout) || (count < SERTESTLEN))
  283.    {
  284.     Message(I_DONT_AGREE);
  285.     Packet.Len = 1;
  286.     Packet.Data[0] = '1';
  287.     if((Error = SendPacket())) return Error;
  288.     CurrSpeed--;
  289.    }
  290.    else
  291.    {
  292.     Message(I_AGREED);
  293.     Packet.Len = 1;
  294.     Packet.Data[0] = '!';
  295.     if((Error = SendPacket())) return Error;
  296.     Message(SPEED_DONE);
  297.     done = TRUE;
  298.    }
  299.   }
  300.   else 
  301.   {
  302.    Message(SERVER_DONT_AGREE);
  303.    if((Error = PutSynch())) return Error;
  304.    CurrSpeed--;
  305.   }
  306.   if((Error = GetSynch())) return Error;
  307.  }while((!done) && (CurrSpeed >= 0));
  308.  if(CurrSpeed < 0) return ERROR_NoSpeed;
  309.  return NO_ERROR;
  310. }
  311.  
  312.  
  313. VOID FMode(VOID)
  314. {
  315.  if(Mode == TEXT) Mode = BIN;
  316.  else Mode = TEXT;
  317.  Gads[TEXTBIN - 1].GadgetText = &Texts[6 + Mode];
  318.  RefreshGList(&Gads[TEXTBIN - 1],MainWin,NULL,1);
  319. }
  320.  
  321. VOID Activate(LONG Cause)
  322. {
  323.  if(Cause == AM)
  324.  {
  325.   if(Active != AM)
  326.   {
  327.    Borders[41].FrontPen = 1;
  328.    Borders[40].FrontPen = 2;
  329.    Borders[39].FrontPen = 2;
  330.    Borders[38].FrontPen = 1;
  331.    Borders[38].NextBorder = NULL;
  332.    DrawBorder(MainWin->RPort,&Borders[41],0,0);
  333.    Borders[38].NextBorder = &Borders[37]; 
  334.    if(Gads[0].GadgetText != &Texts[0])
  335.    { 
  336.     Gads[0].GadgetText = &Texts[1];
  337.     RefreshGList(&Gads[0],MainWin,NULL,1);
  338.    }   
  339.    Active = AM;
  340.   }
  341.  }
  342.  else if(Cause == PC)
  343.  {
  344.   if(Active != PC)
  345.   {
  346.    Borders[41].FrontPen = 2;
  347.    Borders[40].FrontPen = 1;
  348.    Borders[39].FrontPen = 1;
  349.    Borders[38].FrontPen = 2;
  350.    Borders[38].NextBorder = NULL;
  351.    DrawBorder(MainWin->RPort,&Borders[41],0,0);
  352.    Borders[38].NextBorder = &Borders[37];
  353.    if(Gads[0].GadgetText != &Texts[0])
  354.    { 
  355.     Gads[0].GadgetText = &Texts[2];
  356.     RefreshGList(&Gads[0],MainWin,NULL,1);
  357.    }   
  358.    Active = PC;
  359.   }
  360.  }
  361. }
  362.  
  363.  
  364.  
  365. VOID Configure(VOID)
  366. {
  367.  LONG count, Done = FALSE;
  368.  LONG Err = FALSE;
  369.  USHORT GadgetNum;
  370.  struct Gadget *GadgetPtr; 
  371.  struct IntuiMessage *message;
  372.  struct Window *ConfigWin;
  373.  SHORT tempMethod = Method,tempSpeed = MSpeed,t1,t2;
  374.  
  375.  if(Gads[0].GadgetText != &Texts[0]) /* start */  { FMode(); return; }
  376.  
  377.  sprintf(UnitBuff,"%d",UnitNum % 100);
  378.  UnitInfo.LongInt = UnitNum;
  379.  sprintf(DelayBuff,"%d",DelayTime % 100);
  380.  DelayInfo.LongInt = DelayTime;
  381.  sprintf(CheckBuff,"%d",CheckTime % 100);
  382.  CheckInfo.LongInt = CheckTime;
  383.  sprintf(CheckSumBuff,"%d",CheckSumTry % 100);
  384.  CheckSumInfo.LongInt = CheckSumTry;
  385.  strcpy(SerNameBuff,SerialName); 
  386.  if(tempMethod == BIOS)
  387.   ConfigGads[2].GadgetText = &ConfigTexts[3];
  388.  else 
  389.   ConfigGads[2].GadgetText = &ConfigTexts[4];
  390.  ConfigWindow.Screen = MainScr;
  391.  if(!(ConfigWin = (struct Window *) OpenWindow(&ConfigWindow))) return;
  392.  DrawBorder(ConfigWin->RPort,&ConfigBorders[11],330,84); 
  393.  PrintIText(ConfigWin->RPort,&ConfigTexts[14],0,0);
  394.  PrintIText(ConfigWin->RPort,&SpeedTexts[tempSpeed - 1],332,84);
  395.  t1 = LeftArrow.PlanePick;
  396.  t2 = RightArrow.LeftEdge;
  397.  RightArrow.LeftEdge = 118;
  398.  LeftArrow.PlanePick = RightArrow.PlanePick = 1;
  399.  DrawImage(ConfigWin->RPort,&RightArrow,310,1);
  400.  LeftArrow.PlanePick = RightArrow.PlanePick = t1;
  401.  RightArrow.LeftEdge = t2;  
  402.  do
  403.  {
  404.   WaitPort(ConfigWin->UserPort);
  405.   while(message = (struct IntuiMessage *)GetMsg(ConfigWin->UserPort))
  406.   {
  407.    GadgetPtr = (struct Gadget *)message->IAddress;
  408.    GadgetNum = GadgetPtr->GadgetID;
  409.    ReplyMsg((struct Message *) message);
  410.    switch (GadgetNum)
  411.    {
  412.     case SPEEDL: if(tempSpeed > MINSPEED) tempSpeed--;
  413.                  PrintIText(ConfigWin->RPort,&SpeedTexts[tempSpeed -1],332,84);
  414.                  break;
  415.  
  416.     case SPEEDR: if(tempSpeed < MaxSpeed[tempMethod]) tempSpeed++;
  417.                  PrintIText(ConfigWin->RPort,&SpeedTexts[tempSpeed -1],332,84);
  418.                  break;
  419.  
  420.     case USEBIOS:
  421.                  if(tempMethod == BIOS)
  422.                  {
  423.                   tempMethod = HARD;
  424.                  ConfigGads[2].GadgetText = &ConfigTexts[4];
  425.                  }
  426.                  else
  427.                  {
  428.                   tempMethod = BIOS;
  429.                   ConfigGads[2].GadgetText = &ConfigTexts[3];
  430.                   if(tempSpeed > MaxSpeed[tempMethod])
  431.                   {
  432.                    tempSpeed = MaxSpeed[tempMethod];
  433.                    PrintIText(ConfigWin->RPort,&SpeedTexts[tempSpeed-1],332,84);
  434.                   }
  435.                  }
  436.                  RefreshGList(&ConfigGads[2],ConfigWin,NULL,1);
  437.                  break;                    
  438.     case OK: 
  439.             if(SerNameBuff[0] != NULL) 
  440.              strcpy(SerialName,SerNameBuff);
  441.             else 
  442.              strcpy(SerialName,"serial.device");
  443.  
  444.             if((UnitBuff[0] != NULL) && (UnitInfo.LongInt >= 0))
  445.              UnitNum  = UnitInfo.LongInt;
  446.             else UnitNum = DEFUNIT;
  447.  
  448.             if((DelayBuff[0] != NULL) && (DelayInfo.LongInt > 0))
  449.              DelayTime = DelayInfo.LongInt;
  450.             else DelayTime = DEFDELAY;
  451.  
  452.             if((CheckBuff[0] != NULL) && (CheckInfo.LongInt >= 0))
  453.              CheckTime  = CheckInfo.LongInt;
  454.             else CheckTime = DEFCHECK;
  455.  
  456.            if((CheckSumBuff[0] != NULL) && (CheckSumInfo.LongInt >= 0))
  457.              CheckSumTry  = CheckSumInfo.LongInt;
  458.             else CheckSumTry = DEFCHECKSUM;
  459.  
  460.             Method = tempMethod;
  461.             MSpeed = tempSpeed;
  462.             Done = TRUE;
  463.  
  464.             break;
  465.     case SAVE: Err = FALSE;
  466.                ConfigFile = fopen(ConfigFileName,"w");
  467.                if(ConfigFile)
  468.                {
  469.                 if(SerNameBuff[0] != NULL)
  470.                  { if(!fprintf(ConfigFile,"%s\n",SerNameBuff)) Err = TRUE; }
  471.                 else 
  472.                  if(!fprintf(ConfigFile,"%s\n",SerialName)) Err = TRUE;
  473.  
  474.                 if(UnitInfo.LongInt >= 0)
  475.                  {if(!fprintf(ConfigFile,"%d\n",UnitInfo.LongInt)) Err = TRUE;}
  476.                 else
  477.                  if(!fprintf(ConfigFile,"%d\n",UnitNum)) Err = TRUE;
  478.  
  479.                 if(DelayInfo.LongInt > 0)
  480.                  {if(!fprintf(ConfigFile,"%d\n",DelayInfo.LongInt)) Err = TRUE;}
  481.                 else
  482.                  if(!fprintf(ConfigFile,"%d\n",DelayTime)) Err = TRUE;
  483.  
  484.                 if(CheckInfo.LongInt >= 0)
  485.                  {if(!fprintf(ConfigFile,"%d\n",CheckInfo.LongInt)) Err = TRUE;}
  486.                 else
  487.                  if(!fprintf(ConfigFile,"%d\n",CheckTime)) Err = TRUE;
  488.  
  489.                 if(CheckSumInfo.LongInt >= 0)
  490.                  {if(!fprintf(ConfigFile,"%d\n",CheckSumInfo.LongInt)) Err = TRUE;}
  491.                 else
  492.                  if(!fprintf(ConfigFile,"%d\n",CheckSumTry)) Err = TRUE;
  493.  
  494.                 if(!fprintf(ConfigFile,"%d\n",tempSpeed)) Err = TRUE;
  495.                 if(!fprintf(ConfigFile,"%d\n",tempMethod)) Err = TRUE;
  496.                 fclose(ConfigFile);
  497.                }
  498.                else Err = TRUE;
  499.                break;  
  500.  
  501.     case CANCEL:
  502.                  strcpy(SerNameBuff,SerialName);
  503.                  UnitInfo.LongInt = UnitNum;
  504.                  DelayInfo.LongInt = DelayTime;
  505.                  CheckInfo.LongInt = CheckTime;
  506.                  CheckSumInfo.LongInt = CheckSumTry;
  507.                  Done = TRUE;
  508.                  break;
  509.  
  510.     case SERNAME: if(SerNameBuff[0] != NULL) 
  511.                    strcpy(SerialName,SerNameBuff);
  512.                   else
  513.                   {
  514.                    strcpy(SerialName,"serial.device");
  515.                    strcpy(SerNameBuff,"serial.device");
  516.                   }
  517.                   RefreshGList(&ConfigGads[6],ConfigWin,NULL,1);
  518.                   break;
  519.  
  520.     case UNIT: if(UnitInfo.LongInt >= 0)
  521.                 UnitNum = UnitInfo.LongInt;
  522.                else UnitInfo.LongInt = UnitNum = DEFUNIT;
  523.                sprintf(UnitBuff,"%d",UnitNum);
  524.                RefreshGList(&ConfigGads[7],ConfigWin,NULL,1);
  525.                break;
  526.  
  527.     case DELAY: if(DelayInfo.LongInt > 0)
  528.                  DelayTime = DelayInfo.LongInt;
  529.                 else DelayInfo.LongInt = DelayTime = DEFDELAY;
  530.                 sprintf(DelayBuff,"%d",DelayTime);
  531.                 RefreshGList(&ConfigGads[8],ConfigWin,NULL,1);
  532.                 break;
  533.  
  534.     case CHECK: if(CheckInfo.LongInt >= 0)
  535.                  CheckTime = CheckInfo.LongInt;
  536.                 else CheckInfo.LongInt = CheckTime = DEFCHECK;
  537.                 sprintf(CheckBuff,"%d",CheckTime);
  538.                 RefreshGList(&ConfigGads[9],ConfigWin,NULL,1);
  539.                 break;
  540.  
  541.     case CHECKSUM: if(CheckSumInfo.LongInt >= 0)
  542.                     CheckSumTry = CheckSumInfo.LongInt;
  543.                    else CheckSumInfo.LongInt = CheckSumTry = DEFCHECKSUM;
  544.                    sprintf(CheckSumBuff,"%d",CheckSumTry);
  545.                    RefreshGList(&ConfigGads[10],ConfigWin,NULL,1);
  546.                    break;
  547.     default: break;
  548.    } 
  549.   }
  550.  }while(!Done);
  551.  if(ConfigWin) CloseWindow(ConfigWin);
  552.  DrawImage(MainWin->RPort,&DownArrow,297,5);
  553.  DrawImage(MainWin->RPort,&DownArrow,328,5);
  554.  DrawImage(MainWin->RPort,&RightArrow,5,23);
  555.  DrawImage(MainWin->RPort,&RightArrow,354,23);
  556.  DrawBorder(MainWin->RPort,(struct Border *) &Borders[41],0,0);
  557.  PrintIText(MainWin->RPort,&Texts[12],110,120); 
  558.  PrintIText(MainWin->RPort,&Texts[13],430,120); 
  559.  DrawImage(MainWin->RPort,&NameImage, 20,185);  
  560.  for(count = 0; count < 4; count++)
  561.  {
  562.   if(MessNum[count] != -1)
  563.   {
  564.    strcpy(MessIntuiText[count].IText,MessageT[MessNum[count]]);
  565.    PrintIText(MainWin->RPort, &MessIntuiText[count],8,0);
  566.   } 
  567.  }
  568.  if(Err) Message(ERROR_WriteConfig);
  569. }
  570.  
  571.  
  572. VOID FreeFInfo(LONG Cause)
  573. {
  574.  struct FInfo *next;
  575.  
  576.  while(First[Cause])
  577.  {
  578.   next = First[Cause]->next;
  579.   free(First[Cause]);
  580.   First[Cause] = next;
  581.  }
  582.  FileNum[Cause] = 0;
  583.  PGHInfo[Cause].HorizBody = MAXBODY; 
  584.  PGVInfo[Cause].VertBody = MAXBODY;
  585.  NewModifyProp(&Gads[PCVPROP + Cause - 1],MainWin,NULL,PGVInfo[Cause].Flags,
  586.                PGVInfo[Cause].HorizPot,PGVInfo[Cause].VertPot,
  587.                PGVInfo[Cause].HorizBody,PGVInfo[Cause].VertBody,1);
  588.  
  589.  NewModifyProp(&Gads[PCHPROP + Cause - 1],MainWin,NULL,PGHInfo[Cause].Flags,
  590.               PGHInfo[Cause].HorizPot,PGHInfo[Cause].VertPot,
  591.               PGHInfo[Cause].HorizBody,PGHInfo[Cause].VertBody,1);
  592. }
  593.  
  594.  
  595. VOID ClearDir(LONG Cause)
  596. {
  597.  struct Gadget *Selected;
  598.  long count;
  599.  
  600.  Selected = (Cause == AM) ? AMSelect : PCSelect;
  601.  FreeFInfo(Cause);
  602.  RemoveGList(MainWin,Selected,MAXFILENUM);
  603.  for(count = 0;count < MAXFILENUM;count++)
  604.  {
  605.   strncpy(String[Cause][count],
  606.                    "                                   ", MAXDISPLAY);
  607.   String[Cause][count][MAXDISPLAY] = NULL;
  608.  }
  609.  AddGList(MainWin,Selected,-1,MAXFILENUM,NULL);
  610.  RefreshGList(Selected,MainWin,NULL,MAXFILENUM);
  611. }
  612.  
  613. VOID HandleCd(LONG Cause);
  614.  
  615. VOID EntrySelect(LONG Cause, LONG GadNum)
  616. {
  617.  struct Gadget *Selected;
  618.  static ULONG PrevSec = 0,PrevMic = 0;
  619.  static long SelGad = -1;
  620.  char *Buff,Sep;
  621.  long buffLen;
  622.  
  623.  Selected = (Cause == PC) ? PCSelect : AMSelect;
  624.  Activate(Cause);
  625.  if((GadNum + 1) > FileNum[Cause])
  626.  {
  627.   if(Selected[GadNum].Flags & SELECTED) Selected[GadNum].Flags &= ~SELECTED;
  628.   strncpy(String[Cause][GadNum],
  629.                    "                                   ", MAXDISPLAY);
  630.   String[Cause][GadNum][MAXDISPLAY] = NULL;
  631.   RefreshGList(&Selected[GadNum],MainWin,NULL,1);
  632.   return;
  633.  } 
  634.  RemoveGList(MainWin,Selected,MAXFILENUM); 
  635.  if(Selected[GadNum].Flags & SELECTED)
  636.  {
  637.   if(ItemAddr[Cause][GadNum]->type == FILETYPE)
  638.    SelTexts[Cause][GadNum].FrontPen = DPEN;
  639.   else
  640.    SelTexts[Cause][GadNum].FrontPen = FPEN;
  641.   ItemAddr[Cause][GadNum]->Selected = TRUE;
  642.  }
  643.  else
  644.  {
  645.   if(ItemAddr[Cause][GadNum]->type == FILETYPE)
  646.    SelTexts[Cause][GadNum].FrontPen = FPEN;
  647.   else
  648.    SelTexts[Cause][GadNum].FrontPen = DPEN;
  649.   ItemAddr[Cause][GadNum]->Selected = FALSE;
  650.  }
  651.  AddGList(MainWin,Selected,-1,MAXFILENUM,NULL);
  652.  RefreshGList(Selected,MainWin,NULL,MAXFILENUM);
  653.  
  654.  if(ItemAddr[Cause][GadNum]->type == DIRTYPE)
  655.  {
  656.   if( (GadNum == SelGad) && DoubleClick(PrevSec,PrevMic,NowSec,NowMic))
  657.   {
  658.    Buff = (Cause == PC) ? PCBuff : AMBuff;
  659.    if(strlen(ItemAddr[Cause][GadNum]->name) + strlen(Buff) < BUFFLEN - 1)
  660.    {
  661.     Sep = (Cause == PC) ? '\\' : '/';
  662.     buffLen = strlen(Buff);
  663.     if(Buff[buffLen - 1] != Sep)
  664.     {
  665.      if(!((Cause == AM) && (Buff[buffLen - 1] == ':')))
  666.      { 
  667.       Buff[buffLen] = Sep;
  668.       Buff[buffLen + 1] = NULL;
  669.      }
  670.     }
  671.     strcat(Buff,ItemAddr[Cause][GadNum]->name);
  672.     HandleCd(Cause);
  673.    }
  674.   }
  675.   PrevSec = NowSec;
  676.   PrevMic = NowMic;
  677.   SelGad = GadNum;
  678.  }
  679. }
  680.  
  681.  
  682. VOID ModifyP(LONG Pos, LONG Cause)
  683. {
  684.  LONG vbody;
  685.  USHORT vb;
  686.  
  687.  if (FileNum[Cause] <= MAXFILENUM) vbody = MAXBODY;
  688.  else vbody = (MAXBODY * MAXFILENUM) / FileNum[Cause];
  689.  vb = (USHORT)vbody;
  690.  NewModifyProp(&Gads[PCVPROP + Cause - 1],MainWin,NULL,PGVInfo[Cause].Flags,
  691.                PGVInfo[Cause].HorizPot,Pos,PGVInfo[Cause].HorizBody,vb,1);
  692.  OldVPot[Cause] = Pos;
  693.  
  694.  NewModifyProp(&Gads[PCHPROP + Cause - 1],MainWin,NULL,PGHInfo[Cause].Flags,
  695.               PGHInfo[Cause].HorizPot,PGHInfo[Cause].VertPot,
  696.               MAXBODY / 2,PGHInfo[Cause].VertBody,1);
  697.  
  698.  
  699. VOID HandleDir(VOID)
  700. {
  701.  LONG Error;
  702.  struct FInfo *tmp; 
  703.  short count,ActualNum;
  704.  struct Gadget *Selected;
  705.  long Cause;
  706.  
  707.  if(Active == PC)
  708.  {
  709.   Selected = PCSelect;
  710.   Cause = PC;
  711.  }
  712.  else
  713.  {
  714.   Selected = AMSelect;
  715.   Cause = AM;
  716.  }
  717.  RemoveGList(MainWin,Selected,MAXFILENUM); 
  718.  for(count = 0; count < MAXFILENUM; count++)
  719.   Selected[count].Flags &= ~SELECTED;
  720.  AddGList(MainWin,Selected,-1,MAXFILENUM,NULL);
  721.  RefreshGList(Selected,MainWin,NULL,MAXFILENUM);
  722.  if(First[Cause]) ClearDir(Cause);
  723.  
  724.  WaitPointer();
  725.  if(Cause == AM) 
  726.  {
  727.   if((Error = LocalDir())) Message(Error);
  728.   else Message(SUCCESS);
  729.  }
  730.  else 
  731.  {
  732.   if((Error = RemoteDir())) Message(Error);
  733.   else Message(SUCCESS);
  734.  }
  735.  ActualNum = min(MAXFILENUM,FileNum[Cause]);
  736.  NormalPointer();
  737.  
  738.  if(ActualNum > 0)
  739.  {
  740.   RemoveGList(MainWin,Selected,MAXFILENUM); 
  741.   for(tmp = First[Cause],count = 0; count < ActualNum; tmp = tmp->next,count++) 
  742.   {
  743.    ItemAddr[Cause][count] = tmp;
  744.    if(tmp->type == FILETYPE)
  745.     SelTexts[Cause][count].FrontPen = FPEN;
  746.    else 
  747.     SelTexts[Cause][count].FrontPen = DPEN;
  748.    strncpy(String[Cause][count],&(tmp->data[HPos[Cause]]), MAXDISPLAY);
  749.    String[Cause][count][MAXDISPLAY] = NULL;
  750.   }
  751.   AddGList(MainWin,Selected,-1,MAXFILENUM,NULL);
  752.   RefreshGList(Selected,MainWin,NULL,MAXFILENUM);
  753.   ModifyP(0,Cause);
  754.  }
  755. }
  756.  
  757.  
  758. VOID CloseAll(LONG RetCode)
  759. {
  760.  if(UpData) FreeMem(UpData,sizeof(Up));
  761.  if(DownData) FreeMem(DownData,sizeof(Down));
  762.  if(LeftData) FreeMem(LeftData,sizeof(Left));
  763.  if(RightData) FreeMem(RightData,sizeof(Right));
  764.  if(MainWin) CloseWindow(MainWin);
  765.  if(MainScr) CloseScreen(MainScr);
  766. // if(DOSBase) CloseLibrary((struct Library *)DOSBase);
  767.  if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  768.  if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  769.  if(OrigPath[0]) chdir(OrigPath);
  770.  CloseSerial();
  771.  exit(RetCode);
  772. }
  773.  
  774.  
  775. VOID OpenAll(VOID)
  776. {
  777.  LONG Err;
  778.  char ConfigBuffer[101];
  779.  
  780.  if(!(IntuitionBase = (struct IntuitionBase *) 
  781.                           OpenLibrary("intuition.library",0L))) CloseAll(20L);
  782.  
  783.  if (!(GfxBase = (struct GfxBase *)
  784.                           OpenLibrary("graphics.library",0L))) CloseAll(20L);
  785.  
  786. // if (!(DOSBase = (struct DOSBase *)
  787. //                               OpenLibrary("dos.library",0L))) CloseAll(20L);
  788.  if(!(MainScr = (struct Screen *) OpenScreen(&MyScreen))) CloseAll(10L);
  789.  LoadRGB4(&(MainScr->ViewPort),ColourTable,4);
  790.  
  791.  MyWindow.Screen = MainScr;
  792.  if(!(MainWin = (struct Window *) OpenWindow(&MyWindow))) CloseAll(10L); 
  793.  
  794.  UpData = (USHORT *) AllocMem(sizeof(Up),MEMF_CHIP);
  795.  DownData = (USHORT *) AllocMem(sizeof(Down),MEMF_CHIP);
  796.  LeftData = (USHORT *) AllocMem(sizeof(Left),MEMF_CHIP);
  797.  RightData = (USHORT *) AllocMem(sizeof(Right),MEMF_CHIP);
  798.  CopyMem(Up,UpData,sizeof(Up));
  799.  CopyMem(Down,DownData,sizeof(Down));
  800.  CopyMem(Left,LeftData,sizeof(Left));
  801.  CopyMem(Right,RightData,sizeof(Right));
  802.  UpArrow.ImageData = UpData;
  803.  DownArrow.ImageData = DownData;
  804.  LeftArrow.ImageData = LeftData;
  805.  RightArrow.ImageData = RightData;
  806.  DrawImage(MainWin->RPort,&DownArrow,297,5);
  807.  DrawImage(MainWin->RPort,&DownArrow,328,5);
  808.  DrawImage(MainWin->RPort,&RightArrow,5,23);
  809.  DrawImage(MainWin->RPort,&RightArrow,354,23);
  810.  DrawBorder(MainWin->RPort,&Borders[41],0,0); 
  811.  PrintIText(MainWin->RPort,&Texts[12],110,120); 
  812.  PrintIText(MainWin->RPort,&Texts[13],430,120); 
  813.  DrawImage(MainWin->RPort,&NameImage, 20,185); 
  814.  SelectPos = AddGList(MainWin,AMSelect,-1,MAXFILENUM,NULL);
  815.  SelectPos = AddGList(MainWin,PCSelect,-1,MAXFILENUM,NULL);
  816.  if(getcd(0,OrigPath) == -1) OrigPath[0] = NULL;
  817.  else
  818.  {
  819.   strcpy(AMBuff,OrigPath);
  820.   RefreshGList(&Gads[AMPATH - 1],MainWin,NULL,1);
  821.  }
  822.  Activate(AM);
  823.  Err = FALSE;
  824.  ConfigFile = fopen(ConfigFileName,"r");
  825.  if(ConfigFile)
  826.  {
  827.   fgets(ConfigBuffer, 101, ConfigFile);
  828.   if(ConfigBuffer[0] == NULL) Err = TRUE;
  829.   if(ConfigBuffer[strlen(ConfigBuffer) - 1] == '\n')
  830.    ConfigBuffer[strlen(ConfigBuffer) - 1] = NULL;
  831.   strcpy(SerialName,ConfigBuffer);
  832.  
  833.   fgets(ConfigBuffer, 101, ConfigFile);
  834.   UnitNum = atoi(ConfigBuffer);
  835.   if((UnitNum < 0) || (UnitNum > 99)) Err = TRUE;
  836.  
  837.   fgets(ConfigBuffer, 101, ConfigFile);
  838.   DelayTime = atoi(ConfigBuffer);
  839.   if((DelayTime <= 0) || (DelayTime > 99)) Err = TRUE;
  840.  
  841.   fgets(ConfigBuffer, 101, ConfigFile);
  842.   CheckTime = atoi(ConfigBuffer);
  843.   if((CheckTime < 0) || (CheckTime > 99)) Err = TRUE;
  844.  
  845.   fgets(ConfigBuffer, 101, ConfigFile);
  846.   CheckSumTry = atoi(ConfigBuffer);
  847.   if((CheckSumTry < 0) || (CheckSumTry > 99)) Err = TRUE;
  848.  
  849.   fgets(ConfigBuffer, 101, ConfigFile);
  850.   MSpeed = atoi(ConfigBuffer);
  851.   if((MSpeed <= 0) || (MSpeed > MAXHARDSPEED)) Err = TRUE;
  852.  
  853.   fgets(ConfigBuffer, 101, ConfigFile);
  854.   Method = atoi(ConfigBuffer);
  855.   if((Method < 0) || (Method > 1)) Err = TRUE;
  856.   fclose(ConfigFile);
  857.   if(Err) Message(ERROR_ReadConfig);
  858.  }
  859.  else Err = TRUE;
  860.  if(Err)
  861.  {
  862.   MSpeed = MAXHARDSPEED;
  863.   Method = HARD;
  864.   UnitNum = DEFUNIT;
  865.   DelayTime = DEFDELAY;
  866.   CheckTime = DEFCHECK;
  867.   CheckSumTry = DEFCHECKSUM;
  868.   strcpy(SerialName,"serial.device");
  869.  }
  870. }
  871.  
  872.  
  873. VOID MoveHoriz(LONG Direction, LONG ByUser, LONG Cause)
  874. {
  875.  int count;
  876.  struct IntuiMessage *message;
  877.  struct Gadget *Selected;
  878.  long ActualNum;
  879.  
  880.  ActualNum = min(MAXFILENUM,FileNum[Cause]);
  881.  do
  882.  {
  883.   if(Direction == LEFT) 
  884.   {
  885.    if(HPos[Cause] >= (DirLen[Cause] - MAXDISPLAY)) return;  
  886.    HPos[Cause]++;
  887.   }
  888.   else 
  889.   {
  890.    if(HPos[Cause] == 0) return; 
  891.    HPos[Cause]--;
  892.   } 
  893.   Selected = (Cause == AM) ? AMSelect : PCSelect;
  894.   RemoveGList(MainWin,Selected,MAXFILENUM);
  895.   for(count = 0;count < ActualNum;count++)
  896.   {
  897.    strncpy(String[Cause][count],
  898.                    &(ItemAddr[Cause][count]->data[HPos[Cause]]), MAXDISPLAY);
  899.    String[Cause][count][MAXDISPLAY] = NULL;
  900.   }
  901.   AddGList(MainWin,Selected,-1,MAXFILENUM,NULL);
  902.   RefreshGList(Selected,MainWin,NULL,MAXFILENUM);
  903.   if(ByUser)
  904.   {
  905.    if(Direction == LEFT)
  906.     OldHPot[Cause] = OldHPot[Cause] + MAXBODY / (DirLen[Cause] - MAXDISPLAY);
  907.    else
  908.     OldHPot[Cause] = OldHPot[Cause] - MAXBODY / (DirLen[Cause] - MAXDISPLAY);
  909.    NewModifyProp(&Gads[PCHPROP + Cause - 1],MainWin,NULL,PGHInfo[Cause].Flags,
  910.                  OldHPot[Cause],PGHInfo[Cause].VertPot,
  911.                  PGHInfo[Cause].HorizBody,PGHInfo[Cause].VertBody,1);
  912.   }
  913.   if(!ByUser) break;
  914.   message = (struct IntuiMessage *)GetMsg(MainWin->UserPort);
  915.  } while(message == NULL);
  916.  if(ByUser) ReplyMsg((struct Message *) message);
  917. }
  918.  
  919.  
  920.  
  921. VOID MoveVert(LONG Direction, LONG ByUser, LONG Cause)
  922. {
  923.  int count;
  924.  struct Gadget *Selected;
  925.  struct IntuiMessage *message;
  926.  long ActualNum;
  927.  
  928.  if(FileNum[Cause] <= MAXFILENUM) return; 
  929.  ActualNum = MAXFILENUM;
  930.  do
  931.  { 
  932.   if(Direction == UP)
  933.   { 
  934.    if(ItemAddr[Cause][MAXFILENUM - 1]->next == NULL) 
  935.    {
  936.     if(ByUser) ModifyP(-1,Cause);
  937.     return;
  938.    }
  939.   }
  940.   else
  941.   {
  942.    if(ItemAddr[Cause][0]->prev == NULL) 
  943.    {
  944.     if(ByUser) ModifyP(0,Cause);
  945.     return;
  946.    }
  947.   }
  948.   Selected = (Cause == AM) ? AMSelect : PCSelect;
  949.   RemoveGList(MainWin,Selected,MAXFILENUM);
  950.   for(count = 0;count < ActualNum;count++)
  951.   {
  952.    if(Direction == UP)
  953.     ItemAddr[Cause][count] = ItemAddr[Cause][count]->next; 
  954.    else
  955.     ItemAddr[Cause][count] = ItemAddr[Cause][count]->prev;
  956.    
  957.    if(ItemAddr[Cause][count]->Selected) 
  958.    {
  959.     if(ItemAddr[Cause][count]->type == FILETYPE)
  960.      SelTexts[Cause][count].FrontPen = DPEN;
  961.     else
  962.      SelTexts[Cause][count].FrontPen = FPEN;
  963.     Selected[count].Flags |= SELECTED;
  964.    }
  965.    else
  966.    {
  967.     if(ItemAddr[Cause][count]->type == FILETYPE)
  968.      SelTexts[Cause][count].FrontPen = FPEN;
  969.     else
  970.      SelTexts[Cause][count].FrontPen = DPEN; 
  971.     Selected[count].Flags &= ~SELECTED;
  972.    }
  973.    strncpy(String[Cause][count],
  974.                    &(ItemAddr[Cause][count]->data[HPos[Cause]]), MAXDISPLAY);
  975.    String[Cause][count][MAXDISPLAY] = NULL;
  976.   }
  977.   AddGList(MainWin,Selected,-1,MAXFILENUM,NULL);
  978.   RefreshGList(Selected,MainWin,NULL,MAXFILENUM);
  979.   if(ByUser)
  980.   {
  981.    if(Direction == UP)
  982.     OldVPot[Cause] = OldVPot[Cause] + MAXBODY / (FileNum[Cause] - MAXFILENUM);
  983.    else
  984.     OldVPot[Cause] = OldVPot[Cause] - MAXBODY / (FileNum[Cause] - MAXFILENUM);
  985.    NewModifyProp(&Gads[PCVPROP + Cause - 1],MainWin,NULL,PGVInfo[Cause].Flags,
  986.                  PGVInfo[Cause].HorizPot,OldVPot[Cause],
  987.                  PGVInfo[Cause].HorizBody,PGVInfo[Cause].VertBody,1);
  988.   }
  989.   if(!ByUser) break;
  990.   message = (struct IntuiMessage *)GetMsg(MainWin->UserPort);
  991.  } while(message == NULL);
  992.  if(ByUser) ReplyMsg((struct Message *) message);
  993. }
  994.  
  995.  
  996. VOID PropHMoved(LONG Cause)
  997. {
  998.  if(OldHPot[Cause] == PGHInfo[Cause].HorizPot) return;
  999.  if(OldHPot[Cause] < PGHInfo[Cause].HorizPot)
  1000.  {
  1001.   while(OldHPot[Cause] < PGHInfo[Cause].HorizPot)
  1002.   {
  1003.    MoveHoriz(LEFT,0,Cause);
  1004.    if(OldHPot[Cause] > (MAXBODY - (MAXBODY / (DirLen[Cause] - MAXDISPLAY))))
  1005.    {
  1006.     OldHPot[Cause] = MAXBODY;
  1007.     break;
  1008.    }
  1009.    OldHPot[Cause] = OldHPot[Cause] + MAXBODY / (DirLen[Cause] - MAXDISPLAY);
  1010.   }
  1011.  }
  1012.  else
  1013.  {
  1014.   while(OldHPot[Cause] > PGHInfo[Cause].HorizPot)
  1015.   {
  1016.    MoveHoriz(RIGHT,0,Cause);
  1017.    if(OldHPot[Cause] < (MAXBODY / (DirLen[Cause] - MAXDISPLAY)))
  1018.    {
  1019.     OldHPot[Cause] = 0;
  1020.     break;
  1021.    } 
  1022.    OldHPot[Cause] = OldHPot[Cause] - MAXBODY / (DirLen[Cause] - MAXDISPLAY);
  1023.   }
  1024.  }
  1025.  NewModifyProp(&Gads[PCHPROP + Cause - 1],MainWin,NULL,PGHInfo[Cause].Flags,
  1026.                OldHPot[Cause],PGHInfo[Cause].VertPot,
  1027.                PGHInfo[Cause].HorizBody,PGHInfo[Cause].VertBody,1);
  1028. }
  1029.  
  1030. VOID PropVMoved(LONG Cause)
  1031. {
  1032.  if (FileNum[Cause] <= MAXFILENUM) return;
  1033.  if(OldVPot[Cause] < PGVInfo[Cause].VertPot) 
  1034.  {
  1035.   while(OldVPot[Cause] < PGVInfo[Cause].VertPot)
  1036.   { 
  1037.    MoveVert(UP,0,Cause);
  1038.    if(OldVPot[Cause] > (MAXBODY - (MAXBODY / (FileNum[Cause] - MAXFILENUM))))
  1039.    {
  1040.     OldVPot[Cause] = MAXBODY;
  1041.     break;
  1042.    }
  1043.    OldVPot[Cause] = OldVPot[Cause] + MAXBODY / (FileNum[Cause] - MAXFILENUM);
  1044.   }
  1045.  }
  1046.  else 
  1047.  {
  1048.   while(OldVPot[Cause] > PGVInfo[Cause].VertPot)
  1049.   {
  1050.    MoveVert(DOWN,0,Cause);
  1051.    if(OldVPot[Cause] < (MAXBODY / (FileNum[Cause] - MAXFILENUM)))
  1052.    {
  1053.     OldVPot[Cause] = 0;
  1054.     break;
  1055.    } 
  1056.    OldVPot[Cause] = OldVPot[Cause] - MAXBODY / (FileNum[Cause] - MAXFILENUM);
  1057.   }
  1058.  }
  1059.  NewModifyProp(&Gads[PCVPROP + Cause - 1],MainWin,NULL,PGVInfo[Cause].Flags,
  1060.                PGVInfo[Cause].HorizPot,OldVPot[Cause],
  1061.                PGVInfo[Cause].HorizBody,PGVInfo[Cause].VertBody,1);
  1062. }
  1063.  
  1064. VOID HandleMakeDir(VOID)
  1065. {
  1066.  LONG Error,Done = FALSE;
  1067.  USHORT GadgetNum;
  1068.  struct Gadget *GadgetPtr; 
  1069.  struct IntuiMessage *message;
  1070.  
  1071.  RemoveGList(MainWin,AMSelect,MAXFILENUM);
  1072.  RemoveGList(MainWin,PCSelect,MAXFILENUM);
  1073.  RemoveGList(MainWin,Gads,AMHPROP);
  1074.  AddGList(MainWin,&DirGad,-1,1,NULL);
  1075.  RefreshGList(&DirGad,MainWin,NULL,1);
  1076.  ActivateGadget(&DirGad,MainWin,NULL); 
  1077.  Message(DIRNAME);
  1078.  do
  1079.  {
  1080.   WaitPort(MainWin->UserPort);
  1081.   message = (struct IntuiMessage *)GetMsg(MainWin->UserPort);
  1082.   GadgetPtr = (struct Gadget *)message->IAddress;
  1083.   GadgetNum = GadgetPtr->GadgetID;
  1084.   ReplyMsg((struct Message *) message);
  1085.   switch (GadgetNum)
  1086.   {
  1087.    case DIRSTRGAD: Done = TRUE; break;
  1088.    default: break;
  1089.   }
  1090.  } while(Done != TRUE);
  1091.  if(DirBuff[0] != NULL)
  1092.  {
  1093.   WaitPointer();
  1094.   if(Active == PC) 
  1095.   {
  1096.    if((Error = RemoteMKDir(DirBuff))) Message(Error);
  1097.    else Message(SUCCESS);
  1098.   }
  1099.   else
  1100.   {
  1101.    if((Error = LocalMKDir(DirBuff))) Message(Error);
  1102.    else Message(SUCCESS);
  1103.   }
  1104.   NormalPointer();
  1105.  }
  1106.  else Message(CANCELED);
  1107.  Borders[15].FrontPen = 0;
  1108.  Borders[14].FrontPen = 0;
  1109.  Borders[13].FrontPen = 0;
  1110.  Borders[12].FrontPen = 0;
  1111.  DirBuff[0] = NULL;
  1112.  RefreshGList(&DirGad,MainWin,NULL,1);
  1113.  RemoveGList(MainWin,&DirGad,1);
  1114.  Borders[15].FrontPen = 2;
  1115.  Borders[14].FrontPen = 1;
  1116.  Borders[13].FrontPen = 1;
  1117.  Borders[12].FrontPen = 2;
  1118.  AddGList(MainWin,Gads,-1,AMHPROP,NULL);
  1119.  AddGList(MainWin,AMSelect,-1,MAXFILENUM,NULL);
  1120.  AddGList(MainWin,PCSelect,-1,MAXFILENUM,NULL);
  1121.  if(NumDone > 0)
  1122.  {
  1123.   RefreshGList(Gads,MainWin,NULL,AMHPROP);
  1124.   RefreshGList(AMSelect,MainWin,NULL,MAXFILENUM);
  1125.   RefreshGList(PCSelect,MainWin,NULL,MAXFILENUM);
  1126.   DrawBorder(MainWin->RPort,&Borders[23],0,0);
  1127.   if(!Error) HandleDir(); 
  1128.  }
  1129.  
  1130.  
  1131. VOID HandleCd(LONG Cause)
  1132. {
  1133.  LONG Error;
  1134.  
  1135.  Activate(Cause);
  1136.  if(Cause == AM)
  1137.  {
  1138.   WaitPointer();
  1139.   Error = LocalCd(AMBuff);
  1140.   RefreshGList(&Gads[AMPATH - 1],MainWin,NULL,1);
  1141.   NormalPointer(); 
  1142.  }
  1143.  else 
  1144.  {
  1145.   if(PCBuff[0] == NULL)
  1146.    strcpy(PCBuff,".");
  1147.   WaitPointer();
  1148.   Error = RemoteCd(PCBuff);
  1149.   strcpy(PCBuff,Packet.Data);
  1150.   RefreshGList(&Gads[PCPATH - 1],MainWin,NULL,1);
  1151.   NormalPointer();
  1152.  }
  1153.  if(!Error) HandleDir();
  1154.  else Message(Error); 
  1155. }
  1156.  
  1157.  
  1158. VOID HandleParent(VOID)
  1159. {
  1160.  if(Active == PC)
  1161.  {
  1162.   strcpy(PCBuff,"..");
  1163.   HandleCd(PC);
  1164.  }
  1165.  else
  1166.  {
  1167.   strcpy(AMBuff,"/");
  1168.   HandleCd(AM);
  1169.  }
  1170. }
  1171.  
  1172.  
  1173. VOID HandleDel(VOID)
  1174. {
  1175.  LONG Error;
  1176.  
  1177.  WaitPointer();
  1178.  if(Active == AM) 
  1179.  {
  1180.   if((Error = LocalDel())) Message(Error);
  1181.   else if(NumDone > 0) Message(SUCCESS);
  1182.   else Message(CANCELED);
  1183.  }
  1184.  else
  1185.  {
  1186.   if((Error = RemoteDel())) Message(Error); 
  1187.   else if(NumDone > 0) Message(SUCCESS);
  1188.   else Message(CANCELED);
  1189.  }
  1190.  NormalPointer();
  1191.  if(NumDone > 0) HandleDir();
  1192. }
  1193.  
  1194.  
  1195. VOID HandleOverWrite(VOID)
  1196. {
  1197.  if(OverWriteProtect == TRUE)
  1198.  {
  1199.   OverWriteProtect = FALSE;
  1200.   Gads[5].GadgetText = &Texts[10];
  1201.  }
  1202.  else
  1203.  {
  1204.   OverWriteProtect = TRUE;
  1205.   Gads[5].GadgetText = &Texts[9];
  1206.  }
  1207.  RefreshGList(&Gads[5],MainWin,NULL,1);
  1208. }
  1209.  
  1210. VOID HandleComm(VOID)
  1211. {
  1212.  LONG Error,Prev;
  1213.  
  1214.  WaitPointer();
  1215.  if(Gads[0].GadgetText == &Texts[0]) /* connect */
  1216.  {
  1217.   CurrSpeed = MINSPEED - 1;
  1218.   if((Error = OpenSerial()))
  1219.   {
  1220.    Message(Error);
  1221.    CloseSerial();
  1222.    NormalPointer();
  1223.    return;
  1224.   }
  1225.   CurrSpeed = MSpeed - 1;
  1226.  
  1227.   if((Error = PutSpeedMethodDelay()))
  1228.   {
  1229.    Message(Error);
  1230.    CloseSerial();
  1231.    NormalPointer();
  1232.    return;
  1233.   }
  1234.  
  1235.   if((Error = SetSerial()))
  1236.   {
  1237.    Message(Error);
  1238.    CloseSerial();
  1239.    NormalPointer();
  1240.    return;
  1241.   }
  1242.   if(Active == PC) Gads[0].GadgetText = &Texts[2];
  1243.   else if(Active == AM) Gads[0].GadgetText = &Texts[1];
  1244.   RefreshGList(&Gads[0],MainWin,NULL,1);
  1245.   if(Mode == TEXT) Gads[4].GadgetText = &Texts[6];
  1246.   else Gads[4].GadgetText = &Texts[7];
  1247.   Gads[4].NextGadget = &Gads[5];
  1248.   RefreshGList(&Gads[4],MainWin,NULL,2);
  1249.  }
  1250.  else
  1251.  {
  1252.   if(Gads[0].GadgetText == &Texts[2]) /* receive */
  1253.   {
  1254.    if((Error = RemoteReceive())) Message(Error);
  1255.    if(NumDone > 0) 
  1256.    { 
  1257.     if(!Error) Message(SUCCESS);
  1258.     Prev = Active;
  1259.     Active = AM; HandleDir(); Active = Prev;
  1260.    }
  1261.    else Message(CANCELED);
  1262.   }
  1263.   else
  1264.   {
  1265.    if((Error = RemoteSend())) Message(Error);
  1266.    if(NumDone > 0) 
  1267.    { 
  1268.     if(!Error) Message(SUCCESS);
  1269.     Prev = Active;
  1270.     Active = PC; HandleDir(); Active = Prev;
  1271.    }
  1272.    else Message(CANCELED);
  1273.   }
  1274.  }
  1275.  NormalPointer();
  1276. }
  1277.  
  1278. VOID HandleQuit(VOID)
  1279. {
  1280.  Message(InformOfQuit);
  1281.  WaitPointer();
  1282.  RemoteQuit();
  1283.  NormalPointer();
  1284. }
  1285.  
  1286.  
  1287. LONG CheckEsc(VOID)
  1288. {
  1289.  struct IntuiMessage *message;
  1290.  
  1291.  message = (struct IntuiMessage *)GetMsg(MainWin->UserPort);
  1292.  while(message)
  1293.  {
  1294.   if(message->Class != RAWKEY) 
  1295.   { ReplyMsg((struct Message *) message); return NO_ERROR; } 
  1296.   if(message->Code == 0X45) 
  1297.   { ReplyMsg((struct Message *) message); return ERROR_Break; } 
  1298.   ReplyMsg((struct Message *) message);
  1299.   message = (struct IntuiMessage *)GetMsg(MainWin->UserPort);
  1300.  }
  1301.  return NO_ERROR;
  1302. }
  1303.  
  1304. extern struct MsgPort *TimerMP;
  1305. extern struct timerequest *TimerIO;
  1306.  
  1307.  
  1308. extern long Serial_OK;
  1309.  
  1310. VOID main()
  1311. {
  1312.  ULONG Sig;
  1313.  LONG Done = FALSE,Error;
  1314.  USHORT GadgetNum;
  1315.  struct Gadget *GadgetPtr; 
  1316.  struct IntuiMessage *message;
  1317.  SHORT TimerSetup = FALSE;
  1318.  
  1319.  OpenAll();
  1320.  do
  1321.  {
  1322.   if(Serial_OK && (CheckTime > 0) && !OpenTimer())
  1323.   {
  1324.    TimerSetup = TRUE;
  1325.    TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1326.    TimerIO->tr_time.tv_secs = CheckTime;
  1327.    TimerIO->tr_time.tv_micro = 2;
  1328.    SendIO((struct IORequest *)TimerIO);
  1329.    Sig = Wait((1L << (MainWin->UserPort)->mp_SigBit) | 
  1330.               (1L << TimerMP->mp_SigBit));
  1331.    AbortIO((struct IORequest *)TimerIO);
  1332.    WaitIO((struct IORequest *)TimerIO);
  1333.    CloseTimer();
  1334.   } 
  1335.   else
  1336.    Sig = Wait(1L << (MainWin->UserPort)->mp_SigBit);
  1337.   if(Sig & (1L << (MainWin->UserPort)->mp_SigBit))
  1338.   {
  1339.    while(message = (struct IntuiMessage *)GetMsg(MainWin->UserPort))
  1340.    {
  1341.     if(message->Class == RAWKEY) 
  1342.     { 
  1343.      ReplyMsg((struct Message *) message);
  1344.      continue; 
  1345.     }
  1346.     GadgetPtr = (struct Gadget *)message->IAddress;
  1347.     GadgetNum = GadgetPtr->GadgetID;
  1348.     NowSec = message->Seconds;
  1349.     NowMic = message->Micros;
  1350.     ReplyMsg((struct Message *) message);
  1351.     PrintFileName(NULL);
  1352.     ShowRemainder(0,0);
  1353.     ClrSer();
  1354.     switch (GadgetNum)
  1355.     {
  1356.      case EXIT: HandleQuit(); Done = TRUE; break;
  1357.      case COMM: HandleComm(); break;
  1358.      case PARENT: HandleParent(); break;
  1359.      case MKDIR: HandleMakeDir(); break;
  1360.      case CONFIG: Configure(); break;
  1361.      case DELETE: HandleDel(); break;
  1362.      case OVRWRITE: HandleOverWrite(); break; 
  1363.  
  1364.      case PCUP: Activate(PC); MoveVert(DOWN,1,PC); break;
  1365.      case AMUP: Activate(AM); MoveVert(DOWN,1,AM); break;
  1366.      case PCDOWN: Activate(PC); MoveVert(UP,1,PC); break;
  1367.      case AMDOWN: Activate(AM); MoveVert(UP,1,AM); break;
  1368.      case PCVPROP: Activate(PC); PropVMoved(PC); break;
  1369.      case AMVPROP: Activate(AM); PropVMoved(AM); break;
  1370.      case PCLEFT: Activate(PC); MoveHoriz(RIGHT,1,PC); break;
  1371.      case AMLEFT: Activate(AM); MoveHoriz(RIGHT,1,AM); break;
  1372.      case PCRIGHT: Activate(PC); MoveHoriz(LEFT,1,PC); break;
  1373.      case AMRIGHT: Activate(AM); MoveHoriz(LEFT,1,AM); break;
  1374.      case PCHPROP: Activate(PC); PropHMoved(PC); break;
  1375.      case AMHPROP: Activate(AM); PropHMoved(AM); break;
  1376.  
  1377.      case AMPATH: HandleCd(AM); break;
  1378.      case PCPATH: HandleCd(PC); break;
  1379.  
  1380.      case AM1: EntrySelect(AM,0); break;
  1381.      case AM2: EntrySelect(AM,1); break;
  1382.      case AM3: EntrySelect(AM,2); break;
  1383.      case AM4: EntrySelect(AM,3); break;
  1384.      case AM5: EntrySelect(AM,4); break;
  1385.      case AM6: EntrySelect(AM,5); break;
  1386.      case AM7: EntrySelect(AM,6); break;
  1387.      case AM8: EntrySelect(AM,7); break;
  1388.      case AM9: EntrySelect(AM,8); break;
  1389.  
  1390.      case PC1: EntrySelect(PC,0); break;
  1391.      case PC2: EntrySelect(PC,1); break;
  1392.      case PC3: EntrySelect(PC,2); break;
  1393.      case PC4: EntrySelect(PC,3); break;
  1394.      case PC5: EntrySelect(PC,4); break;
  1395.      case PC6: EntrySelect(PC,5); break;
  1396.      case PC7: EntrySelect(PC,6); break;
  1397.      case PC8: EntrySelect(PC,7); break;
  1398.      case PC9: EntrySelect(PC,8); break;
  1399.      default: break;
  1400.     }
  1401.    } /* while Message */
  1402.   }
  1403.   else /* timer! */
  1404.    if((Error = CheckLink())) Message(Error);
  1405.  }while(!Done);
  1406.  if(First[AM]) FreeFInfo(AM);
  1407.  if(First[PC]) FreeFInfo(PC);
  1408.  CloseAll(0);
  1409. }
  1410.